import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        while(n-->0){
            int m = sc.nextInt();
            func(m);
        }
    }
    public static void func(int n){
        for(int i = 2;i<=n/i;i++){
            if(n % i == 0){
                 int s = 0;
            while(n % i == 0){
                n/=i;
                s++;
            }
            System.out.println(i+" "+s);
        }
            }
            //特判
            if(n > 1) System.out.println(n+" " +"1");
           
        System.out.println();
    }
}